package net.realsee.service.wcs.data.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.realsee.common.utils.StringUtils;
import net.realsee.domain.wcs.data.WcsLanguage;
import net.realsee.domain.wcs.data.bo.WcsLanguageBo;
import net.realsee.domain.wcs.data.vo.WcsLanguageVo;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.mapper.wcs.data.WcsLanguageMapper;
import net.realsee.service.wcs.data.IWcsLanguageService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 语言各地区语言清单，遵循windowns标准Service业务层处理
 *
 * @author realsee
 * @date 2023-08-11
 */
@RequiredArgsConstructor
@Service
public class WcsLanguageServiceImpl extends ServiceImpl<WcsLanguageMapper, WcsLanguage> implements IWcsLanguageService {

    private final WcsLanguageMapper baseMapper;

    /**
     * 查询语言各地区语言清单，遵循windowns标准
     */
    @Override
    public WcsLanguageVo selectVoById(Long id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询语言各地区语言清单，遵循windowns标准列表
     */
    @Override
    public TableDataInfo<WcsLanguageVo> selectVoPage(WcsLanguageBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<WcsLanguage> lqw = buildVoQueryWrapper(bo);
        Page<WcsLanguageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询语言各地区语言清单，遵循windowns标准列表
     */
    @Override
    public List<WcsLanguageVo> selectVoList(WcsLanguageBo bo) {
        LambdaQueryWrapper<WcsLanguage> lqw = buildVoQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<WcsLanguage> buildVoQueryWrapper(WcsLanguageBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<WcsLanguage> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getId() != null, WcsLanguage::getId, bo.getId());
        lqw.eq(StringUtils.isNotBlank(bo.getCharacterSet()), WcsLanguage::getCharacterSet, bo.getCharacterSet());
        lqw.eq(bo.getCodePage() != null, WcsLanguage::getCodePage, bo.getCodePage());
        lqw.eq(StringUtils.isNotBlank(bo.getLanguageCode()), WcsLanguage::getLanguageCode, bo.getLanguageCode());
        lqw.eq(StringUtils.isNotBlank(bo.getLocaleCode()), WcsLanguage::getLocaleCode, bo.getLocaleCode());
        lqw.eq(StringUtils.isNotBlank(bo.getFuid()), WcsLanguage::getFuid, bo.getFuid());
        lqw.eq(bo.getTextId() != null, WcsLanguage::getTextId, bo.getTextId());
        lqw.eq(bo.getRefrenceId() != null, WcsLanguage::getRefrenceId, bo.getRefrenceId());
        lqw.eq(bo.getUnitId() != null, WcsLanguage::getUnitId, bo.getUnitId());
        lqw.eq(bo.getDelFlag() != null, WcsLanguage::getDelFlag, bo.getDelFlag());
        lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), WcsLanguage::getCreateBy, bo.getCreateBy());
        lqw.eq(bo.getCreateTime() != null, WcsLanguage::getCreateTime, bo.getCreateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getUpdateBy()), WcsLanguage::getUpdateBy, bo.getUpdateBy());
        lqw.eq(bo.getUpdateTime() != null, WcsLanguage::getUpdateTime, bo.getUpdateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getDeleteBy()), WcsLanguage::getDeleteBy, bo.getDeleteBy());
        lqw.eq(bo.getDeleteTime() != null, WcsLanguage::getDeleteTime, bo.getDeleteTime());
        lqw.eq(bo.getRowVersionStamp() != null, WcsLanguage::getRowVersionStamp, bo.getRowVersionStamp());
        return lqw;
    }

    /**
     * 新增语言各地区语言清单，遵循windowns标准
     */
    @Override
    public Boolean insertByBo(WcsLanguageBo bo) {
        WcsLanguage add = BeanUtil.toBean(bo, WcsLanguage.class);
        return this.save(add);
    }

    /**
     * 修改语言各地区语言清单，遵循windowns标准
     */
    @Override
    public Boolean updateByBo(WcsLanguageBo bo) {
        WcsLanguage update = BeanUtil.toBean(bo, WcsLanguage.class);
        return this.updateById(update);
    }

    /**
     * 批量删除语言各地区语言清单，遵循windowns标准
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids) {
        return this.removeBatchByIds(ids);
    }
}
